/**
 * @file   1075.cpp
 * @author Shuang Hu <hsmath@ubuntu>
 * @date   Wed Apr 14 23:29:27 2021
 * 
 * @brief  PAT judge
 * @time 83 minutes
 * 
 */

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
class Problems{
public:
    int problem_num;
    int full_mark[6]={0};
    Problems(){
	problem_num=0;
    }
    void set_num(int n){
	problem_num=n;
    }
    void set_mark(){
	for(int i=1;i<=problem_num;i++){
	    int score;
	    cin>>score;
	    full_mark[i]=score;
	}
    }
    bool iffull(int num,int mark){//judge whether you get the full mark in a problem
	if(mark==full_mark[num]){
	    return true;
	}else{
	    return false;
	}
    }
};
class candidates{
public:
    int ID;
    int get_mark[6]={0};
    int iftijiao[6]={0};
    int acceptnum;//num of ac problems;
    bool isvisible;//visible or not!
    int sum;
    int rank;
    candidates(){
	isvisible=false;
	acceptnum=0;
	sum=0;
    }
    void set_info(int ID,int num,int score){
	iftijiao[num]=1;
	if(score>=get_mark[num]){
	    get_mark[num]=score;//register the score!
	}
	if(score>=0&&isvisible==false){
	    isvisible=true;
	}
	this->ID=ID;
    }
};
class examDB{
private:
    int stunum;
    vector<candidates> exam;
    Problems P;
public:
    examDB(){
    };
    static bool cmp(candidates C1,candidates C2){
	if(C1.sum>C2.sum){
	    return true;
	}else if(C1.sum==C2.sum){
	    if(C1.acceptnum>C2.acceptnum){
		return true;
	    }else if(C1.acceptnum==C2.acceptnum){
		if(C1.ID<C2.ID){
		    return true;
		}
	    }
	}
	return false;
    }
    void set_info(){
	cin>>stunum;
	exam.resize(stunum);
	int pnum;
	cin>>pnum;
	int admitnum;
	cin>>admitnum;
	P.set_num(pnum);
        P.set_mark();
	for(int i=0;i<admitnum;i++){
	    int ID,ques,score;
	    cin>>ID>>ques>>score;
	    exam[ID-1].set_info(ID,ques,score);
	}
    }
    void handle(){
	for(int i=0;i<stunum;i++){
	    for(int j=1;j<=P.problem_num;j++){
		if(exam[i].get_mark[j]>=0){
		    exam[i].sum=exam[i].sum+exam[i].get_mark[j];
	        }
	    }
	    for(int j=1;j<=P.problem_num;j++){
		if(P.iffull(j,exam[i].get_mark[j])){
		    exam[i].acceptnum++;
		}
	    }
	}
	sort(exam.begin(),exam.end(),cmp);
	exam[0].rank=1;
	for(int i=1;i<stunum;i++){
	    exam[i].rank=i+1;
	    if(exam[i].sum==exam[i-1].sum){
		exam[i].rank=exam[i-1].rank;
	    }
	}
    }
    void Print(){
	for(int i=0;i<stunum;i++){
	    if(exam[i].isvisible==false){
		continue;
	    }
	    cout<<exam[i].rank<<" ";
	    out(exam[i].ID);
	    cout<<" "<<exam[i].sum;
	    for(int j=1;j<=P.problem_num;j++){
		if(exam[i].iftijiao[j]==0){
		    cout<<" -";
		    continue;
		}
		cout<<" "<<exam[i].get_mark[j];
	    }
	    cout<<endl;
	}
    }
    void out(int d){
	if(d>10000){
	    cout<<d;
	}else if(d>1000){
	    cout<<"0"<<d;
	}else if(d>100){
	    cout<<"00"<<d;
	}else if(d>10){
	    cout<<"000"<<d;
	}else{
	    cout<<"0000"<<d;
	}
    }
};
int main(){
    examDB DB;
    DB.set_info();
    DB.handle();
    DB.Print();
};
